package com.dzk.cp.c11x5.index.zx.yl;

import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.dzk.cp.c11x5.index.BaseC11x5Index;
import com.dzk.cp.c11x5.pojo.R5;
import com.dzk.cp.c11x5.util.C11x5Utils;
import com.dzk.cp.c11x5.util.SpringBeanUtils;
import com.dzk.cp.util.CpUtils;

public abstract class ZXnYLIndex extends BaseC11x5Index {
	
private String zxc;
	
	public ZXnYLIndex setParams(int code, int num, int unit, String zxc) {
		super.setParams(code, num, unit);
		this.zxc = zxc;
		return this;
	}
	
	@Override
	public Map<Integer, Integer> index() {
		Map<Integer, Integer> resultMap = new LinkedHashMap<Integer, Integer>();
		int n = getLastestNum();
		List<? extends R5> r5s = SpringBeanUtils.getR5Service(code).queryLatest(n);
		List<String> zxs = Arrays.asList(zxc.split(" "));
		int m = zxs.size();
		int i = -1, j = 0, k = 0;
		for (; k < n; k++) {
			R5 r5 = r5s.get(k);
			List<String> tmpList = Arrays.asList(new String[] {
					CpUtils.fore2zero(r5.getN1()),
					CpUtils.fore2zero(r5.getN2()),
					CpUtils.fore2zero(r5.getN3()),
					CpUtils.fore2zero(r5.getN4()),
					CpUtils.fore2zero(r5.getN5())}).subList(0, m);
			if (C11x5Utils.contain(tmpList, zxs)) {
				resultMap.put(++j, k - i - 1);
				i = k;
			}
		}
		resultMap.put(++j, k - 1 - i);
		return resultMap;
	}
	
	public static ZXnYLIndex getInstance(int code, int num, int unit, String zxc) {
		int n = (zxc.length() + 1 ) / 3;
		switch (n) {
//		case 1:
//			return new ZX1YLIndex().setParams(code, num, unit, zhxc);
		case 2:
			return new ZX2YLIndex().setParams(code, num, unit, zxc);
		case 3:
			return new ZX3YLIndex().setParams(code, num, unit, zxc);
		default:
			return null;
		}
	}

}

class ZX1YLIndex extends ZXnYLIndex {

	@Override
	protected int getZQ() {
		return 11;
	}

}

class ZX2YLIndex extends ZXnYLIndex {

	@Override
	protected int getZQ() {
		return 110 / 2;
	}

}

class ZX3YLIndex extends ZXnYLIndex {

	@Override
	protected int getZQ() {
		return 990 / 6;
	}

}
